#ifndef DUI_H
#define DUI_H

#include <windows.h>
#include <girder4.h>

extern "C" {
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
}

#define WINDOWSGUID			"{7D18B855-91BA-4C97-B24F-85F8EA558621}"
#define FLOWCONTROLGUID		"{FBC54EB3-7744-4636-BDF1-DF8B118D3287}"
#define KEYBOARDGUID		"{3F092C8B-8471-47C7-A531-08E0713CA840}"
#define MOUSEGUID			"{316D1D14-14F3-4484-A21B-C4C17715BF40}"
#define VOLUMEGUID			"{A4420C22-CC79-4711-B78E-A61583D182E9}"
#define GIRDERGUID			"{F02CD0B5-B793-4013-87A9-344588CAD8D0}"
#define MONITORGUID			"{5077B47E-92CC-4297-9A50-D56F3E260301}"
#define OSGUID				"{BB661954-1A7C-4BD7-A1F8-5EC74CE06361}"
#define COMMANDCAPTUREGUID	"{45E3C162-6803-49C3-8BEA-4B1FCFFA9D81}"
#define MISCGUID			"{4FFB8022-9343-4B00-8C46-154C5A547D5C}"
#define GIRDER3LEGACYGUID	"{69C0161F-AD03-4547-9830-AAEA60C26795}"




// For the ParentGUID and ParentCaption use either the defines above and NULL, or your own.
PFTreeNode WINAPI InsertDUIPageEx(PFTree DestTree, PFTree SourceTree, PFTreeNode Node, GUID * ParentGUID, PCHAR ParentCaption);
PFTreeNode WINAPI InsertDUIPageExS(PFTree DestTree, PFTree SourceTree, PFTreeNode Node, PCHAR ParentGUID, PCHAR ParentCaption);
// Use these two if you do not want to store the page in advance.
PFTreeNode WINAPI InsertDUIPageFastS(PFTree DestTree, PFTree SourceTree, PCHAR NodeGUID, PCHAR ParentGUID, PCHAR ParentCaption);
PFTreeNode WINAPI InsertDUIPageFast(PFTree DestTree, PFTree SourceTree, PCHAR NodeGUID, GUID * ParentGUID, PCHAR ParentCaption);


typedef BOOL (WINAPI *MergeCheckProc) ( PDUIItem Item, void * UserData);

#define ACTIONGROUP			"{be45acf0-172f-11da-8cd6-0800200c9a66}"
#define CONDITIONALGROUP	"{d87e0450-172f-11da-8cd6-0800200c9a66}"
#define CONFIGGROUP			"{e56d7ab0-172f-11da-8cd6-0800200c9a66}"
#define SCRIPTCONFIGGROUP	"{e56d7afe-172f-11da-8cd6-0800200c9a66}"


void WINAPI MergeDUITreesEx( PFTree Dest, PFTree Source, MergeCheckProc Proc, void * UserData, int Group );
void WINAPI MergeDUITrees( PFTree Dest, PFTree Source, int Group );
void WINAPI UnmergeDUITrees( PFTree Dest, PFTree Source, int Group );

char * WINAPI GUIDToString(GUID *Guid);
void WINAPI StringToGUID(const char * GuidString, GUID *Guid);

PFTreeNode WINAPI FindNode(GUID * NodeGUID, PFTree Tree, PFTreeNode Node);
PFTreeNode WINAPI FindNodeS(PCHAR NodeGUID, PFTree Tree, PFTreeNode Node);

PFTreeNode WINAPI CreateParentGroup(PFTree Tree, PFTreeNode Parent, GUID *GroupGUID, PCHAR Caption);

BOOL WINAPI RemoveDUIPage(PFTree Tree, GUID * PageGUID);
BOOL WINAPI RemoveDUIPageS(PFTree Tree, PCHAR PageGUID);

PFTree WINAPI LoadDUI(PCHAR filename);

void WINAPI SetCallbacks(PFTree tree, PFTreeNode node, void * Callback, BOOL Children); 

// Lua DUI Handling
BOOL WINAPI ControlSetBool   (lua_State *L, int DuiIndex, PCHAR Control, PCHAR Field, BOOL Value);
BOOL WINAPI ControlGetBool   (lua_State *L, int DuiIndex, PCHAR Control, PCHAR Field, BOOL &Value);
BOOL WINAPI ControlSetString (lua_State *L, int DuiIndex, PCHAR Control, PCHAR Field, const char * Value);
BOOL WINAPI ControlGetString (lua_State *L, int DuiIndex, PCHAR Control, PCHAR Field, char * &Value); // YOU MUST FREE THIS WHEN YOU ARE DONE WITH THE STRING!!
BOOL WINAPI ControlGetNumber (lua_State *L, int DuiIndex, PCHAR Control, PCHAR Field, double &Value);
BOOL WINAPI ControlSetNumber (lua_State *L, int DuiIndex, PCHAR Control, PCHAR Field, double Value);
BOOL WINAPI ControlClear	 (lua_State *L, int DuiIndex);

void WINAPI LuaToAction(lua_State*L, int DuiIndex, int SP, PAction Action, PTarget Target );
void WINAPI ActionToLua(lua_State*L, int DuiIndex, PAction Action, PTarget Target);
BOOL WINAPI LuaToTarget(lua_State *L, int SP, PTarget Target );
void WINAPI TargetToLua(lua_State *L, PTarget Target );
void WINAPI lua_pushaction( lua_State *L, int DuiIndex);

char * WINAPI BoolToString(BOOL v);
BOOL WINAPI StringToBool(PCHAR v);


#ifdef DUILEGACY
// Okay this was no good at all. Please update your plugin to use InsertDUIPageEx or InsertDUIPageExS
#define WINDOW_GROUP	0
#define CONTROLS_GROUP	1
#define MOUSE_GROUP		2
#define GIRDER_GROUP	3
#define FILES_GROUP		4
#define VOLUME_GROUP	5
#define OS_GROUP		6
#define CAPTURE_GROUP	7
#define LEGACY_GROUP	8


typedef struct {
	GUID PageGUID;
	PCHAR Caption;
} sGroups, *pGroups;

sGroups Groups[] = {
	{ {0x7D18B855, 0x91BA, 0x4C97, {0xB2, 0x4F, 0x85, 0xF8, 0xEA, 0x55, 0x86, 0x21}}, "Window"},
	{ {0x4E7A861F, 0x811E, 0x4AB1, {0x88, 0xF6, 0x52, 0x61, 0x95, 0x85, 0x13, 0x67}}, "Controls"},
	{ {0x316D1D14, 0x14F3, 0x4484, {0xA2, 0x1B, 0xC4, 0xC1, 0x77, 0x15, 0xBF, 0x40}}, "Mouse"},
	{ {0xF02CD0B5, 0xB793, 0x4013, {0x87, 0xA9, 0x34, 0x45, 0x88, 0xCA, 0xD8, 0xD0}}, "Girder"},
	{ {0x7327A5E0, 0x3169, 0x436E, {0xAC, 0x28, 0xA6, 0x54, 0x3E, 0x7E, 0xEE, 0x1A}}, "Files"},
	{ {0xA4420C22, 0xCC79, 0x4711, {0xB7, 0x8E, 0xA6, 0x15, 0x83, 0xD1, 0x82, 0xE9}}, "Volume"},
	{ {0xBB661954, 0x1A7C, 0x4BD7, {0xA1, 0xF8, 0x5E, 0xC7, 0x4C, 0xE0, 0x63, 0x61}}, "OS"},
	{ {0x45E3C162, 0x6803, 0x49C3, {0x8B, 0xEA, 0x4B, 0x1F, 0xCF, 0xFA, 0x9D, 0x81}}, "Capture"},
	{ {0x69C0161F, 0xAD03, 0x4547, {0x98, 0x30, 0xAA, 0xEA, 0x60, 0xC2, 0x67, 0x95}}, "Legacy"},
	{ {0,		   0,      0,      {0,    0,    0,    0,    0,    0,    0,    0   }},  NULL },
};

PFTreeNode WINAPI InsertDUIPage(PFTree DestTree, PFTree SourceTree, PFTreeNode Node, GUID * ParentGUID, pGroups Groups);
PCHAR WINAPI FindGroupName(pGroups Group, GUID *GroupGUID);
#endif



#endif